#ifndef _ANSI_HPP_
#define	_ANSI_HPP_

#include "Socket.hpp"
/*******************************************************************************
 ** Name: ansi.hpp                                                            **
 ** Description: WorldObject-derived container objects                        **
 **                                                                           **
 ** Open Source Initiative (OSI) Approved License                             **
 **                                                                           **
 ** The contents of this file are subject to the terms of the                 **
 ** Common Development and Distribution License, Version 1.0 only             **
 ** (the "License").  You may not use this file except in compliance          **
 ** with the License.                                                         **
 **                                                                           **
 ** You can find a copy of the license in the LICENSE file within             **
 ** this distribution or at $WIKI/display/GOVT/License-software.              **
 ** Software distributed under the License is distributed on an "AS IS"       **
 ** basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.           **
 ** See the License for the specific language governing permissions           **
 ** and limitations under the License.                                        **
 **                                                                           **
 ** When distributing Covered Code, include this CDDL header in each          **
 ** file and include the License file at $GAME_DIR/LICENSE.                   **
 ** If applicable, add the following below this header, with the indicated    **
 ** fields enclosed by brackets "[]" replaced with your own identifying       **
 ** information: Portions Copyright [yyyy] [name of copyright owner]          **
 **                                                                           **
 ** Copyright (c) 2009-2011  Barry Gian James <gian@gamingods.net>            **
 ** All rights reserved.                                                      **
 ******************************************************************************/
// Created on March 17, 2010, 8:18 PM
// Modified $Date: 2012-08-14 20:47:30 -0600 (Tue, 14 Aug 2012) $ by $Author: unknown $
#define ansi_hpp_ID   "$Id: ansi.hpp 69068 2012-08-15 02:47:30Z unknown $"

#include "common.hpp"

//! @struct CodeToColor
//! @brief A mapping of embedded color code to ANSI color code
struct CodeToColor
{
	std::string	code;
	std::string	color;
};

enum class ColorCode
{
	Black, Red, DarkRed, Green, DarkGreen, Yellow, Orange, Blue,
	DarkBlue, Magenta, Cyan, Pink, Grey, DarkGrey, LightBlue,
	White, Normal
};
// Embedded color code strings
#define COLOR_CODE_BLACK		"<$black>"
#define COLOR_CODE_RED			"<$red>"
#define COLOR_CODE_DRED			"<$darkred>"
#define COLOR_CODE_GREEN		"<$green>"
#define COLOR_CODE_DGREEN		"<$darkgreen>"
#define COLOR_CODE_YELLOW		"<$yellow>"
#define COLOR_CODE_ORANGE		"<$orange>"
#define COLOR_CODE_BLUE			"<$blue>"
#define COLOR_CODE_DBLUE		"<$darkblue>"
#define COLOR_CODE_MAGENTA		"<$magenta>"
#define COLOR_CODE_DMAGENTA		"<$darkmagenta>"
#define COLOR_CODE_CYAN			"<$cyan>"
#define COLOR_CODE_PINK			"<$pink>"
#define COLOR_CODE_GREY			"<$grey>"
#define COLOR_CODE_DGREY		"<$darkgrey>"
#define COLOR_CODE_LBLUE		"<$lightblue>"
#define COLOR_CODE_WHITE		"<$white>"
#define COLOR_CODE_NORMAL		"<$normal>"

#define ESC_CHAR      '\033'
#define ANSI_ATTR_CMD 'm'

#define ANSI_NORMAL   "\033[0m"

#define ANSI_BOLD       "\033[1m"
#define ANSI_FAINT      "\033[2m"
#define ANSI_UNDER      "\033[4m"
#define ANSI_BLINK_SLOW "\033[5m"
#define ANSI_BLINK_FAST "\033[6m"
#define ANSI_INVERSE    "\033[7m"
#define ANSI_CROSSOUT   "\033[9m"
#define ANSI_BLINK_OFF  "\033[25m"
#define ANSI_CROSSOFF   "\033[29m"

// Foreground colors.
#define ANSI_BLACK      "\033[0;30m"
#define ANSI_DRED        "\033[0;31m"
#define ANSI_DGREEN      "\033[0;32m"
#define ANSI_ORANGE     "\033[0;33m"
#define ANSI_DBLUE       "\033[0;34m"
#define ANSI_DMAGENTA    "\033[0;35m"
#define ANSI_CYAN       "\033[0;36m"
#define ANSI_GREY		"\033[0;37m"
#define ANSI_DGREY		"\033[1;30m"
#define ANSI_RED		"\033[1;31m"
#define ANSI_GREEN		"\033[1;32m"
#define ANSI_YELLOW		"\033[1;33m"
#define ANSI_BLUE		"\033[1;34m"
#define ANSI_PINK		"\033[1;35m"
#define ANSI_LBLUE		"\033[1;36m"
#define ANSI_WHITE      "\033[1;37m"
#define ANSI_DEFAULT_FG "\033[39m"

//#define ANSI_BLACK      "\033[30m"
//#define ANSI_RED        "\033[31m"
//#define ANSI_GREEN      "\033[32m"
//#define ANSI_YELLOW     "\033[33m"
//#define ANSI_BLUE       "\033[34m"
//#define ANSI_MAGENTA    "\033[35m"
//#define ANSI_CYAN       "\033[36m"
//#define ANSI_WHITE      "\033[37m"
//#define ANSI_DEFAULT_FG "\033[39m"

// Background colors.
#define ANSI_BBLACK     "\033[40m"
#define ANSI_BDRED       "\033[41m"
#define ANSI_BDGREEN     "\033[42m"
#define ANSI_BORANGE    "\033[43m"
#define ANSI_BDBLUE      "\033[44m"
#define ANSI_BMAGENTA   "\033[45m"
#define ANSI_BCYAN      "\033[46m"
#define ANSI_BGREY     "\033[47m"
#define ANSI_DEFAULT_BG "\033[49m"
#define ANSI_BDGREY		"\033[50m"
#define ANSI_BRED		"\033[51m"
#define ANSI_BGREEN		"\033[52m"
#define ANSI_BYELLOW	"\033[53m"
#define ANSI_BBLUE		"\033[54m"
#define ANSI_BPINK		"\033[55m"
#define ANSI_BLBLUE		"\033[56m"
#define ANSI_BWHITE		"\033[57m"

//#define ANSI_FRAMED     "\033[51m"
//#define ANSI_OVERLINE   "\033[53m"

// Set Mode
#define ANSI_80x25_CO   "\033[=2h"  // 80x25 color(text)
#define ANSI_640x200_CO "\033[=14h"
#define ANSI_640x480_CO "\033[=18h"


#pragma db object table("color_scheme")
struct ColorScheme
{
	#pragma db id auto
	entity_t	idcolor_scheme;
	std::string name;
	std::string	wallops;
	std::string	normal;
	std::string	combat;
	std::string	portals;
	std::string	emotes;
	std::string	messages;
	std::string	channels;
	std::string	buffs;
	std::string	debuffs;
	std::string	dialogs;
};


// @Deprecated This should be replaced with in-line substitution
/////////////////////////////////////[ Macros
#define FONT_DRED(s)    Socket::Write(s,ANSI_DRED)
#define FONT_BRED(s)	Socket::Write(s,ANSI_RED);
#define FONT_GREEN(s)   Socket::Write(s,ANSI_GREEN)
#define FONT_ORANGE(s)	Socket::Write(s,ANSI_ORANGE)
#define FONT_YELLOW(s)  Socket::Write(s,ANSI_YELLOW)
#define FONT_BLUE(s)    Socket::Write(s,ANSI_BLUE)
#define FONT_DBLUE(s)	Socket::Write(s,ANSI_DBLUE)
#define FONT_LBLUE(s) 	Socket::Write(s,ANSI_LBLUE)
#define FONT_PINK(s)	Socket::Write(s,ANSI_PINK)
#define FONT_MAGENTA(s) Socket::Write(s,ANSI_DMAGENTA)
#define FONT_CYAN(s)    Socket::Write(s,ANSI_CYAN)
#define FONT_WHITE(s)   Socket::Write(s,ANSI_WHITE)
#define FONT_DEFAULT(s) Socket::Write(s,ANSI_DEFAULT_FG)
#define FONT_FAINT(s)	Socket::Write(s,ANSI_FAINT)
#define FONT_BOLD(s)    Socket::Write(s,ANSI_BOLD)
#define FONT_UNDER(s)   Socket::Write(s,ANSI_UNDER)
#define FONT_OVER(s)    Socket::Write(s,ANSI_OVERLINE)
#define FONT_BLINKS(s)  Socket::Write(s,ANSI_BLINK_SLOW)
#define FONT_BLINKF(s)  Socket::Write(s,ANSI_BLINK_FAST)
#define FONT_CROSS(s)   Socket::Write(s,ANSI_CROSSOUT)
#define FONT_INVERSE(s)	Socket::Write(s,ANSI_INVERSE)
#define FONT_NORMAL(s)  Socket::Write(s,ANSI_NORMAL)
#define FONT_BLOOD(s)	Socket::Write(s,ANSI_DRED);
#define FONT_DGREEN(s)	Socket::Write(s,ANSI_DGREEN)


#define FONT_BG_BLACK(s)	Socket::Write(s,ANSI_BBLACK)
#define FONT_BG_RED(s)		Socket::Write(s,ANSI_BRED)
#define FONT_BG_GREEN(s)	Socket::Write(s,ANSI_BGREEN)
#define FONT_BG_YELLOW(s)	Socket::Write(s,ANSI_BYELLOW)
#define FONT_BG_BLUE(s)		Socket::Write(s,ANSI_BBLUE)
#define FONT_BG_MAGENTA(s)	Socket::Write(s,ANSI_BMAGENTA)
#define FONT_BG_CYAN(s)		Socket::Write(s,ANSI_BCYAN)
#define FONT_BG_WHITE(s)	Socket::Write(s,ANSI_BWHITE)
#define FONT_BG_DEFAULT(s)	Socket::Write(s,ANSI_DEFAULT_BG)

const char AnsiToken = '#';
//void TextToColor(int s, const char * ch);

size_t ansi_strlen(const char *);

std::string ReplaceCode(std::string &);

// Color themes

// @Deprecated This is unmaintainable. ~gian
// Object/events that can take color
enum class Colorable
{
	plain, action, say, yell, tell, hit, hitme, immortal, hurt, magic,
	consider, report, poison, social, dying, dead, skill, damage, person,
	npc, bye, gold, note, exit, pvp, who, racetalk, whisper, shout,
	intermud, board,

	max
};

struct ColorToEvent
{
	Colorable	event;
	std::string	color;
};
extern ColorToEvent 	ColorableEvents[];
extern CodeToColor 		ColorCodes[];

#endif /* !_ANSI_H_ */
